
#开始登录
def login(username,passwd):
    # print("登录成功")
    # pass
    if username in admin and admin[username] == passwd:
        return True
def loginu(username,passwd):
    # print("登录成功")
    # pass
    if username in user and user[username] == passwd:
        return True

#查看所有记录
def search():
    # print(mydict)
    print(f"{'ID':<10}{'类别':<15}{'账户':<15}{'金额':<15}{'时间':<15}{'说明':<15}")
    for i in mydict:  # 从字典中取出商品编号、商品名称、单价
        print(f"{i:<8}{mydict[i]['type']:>6}{mydict[i]['count']:>13}{mydict[i]['money']:>14}{mydict[i]['time']:>20}"
              f"{mydict[i]['explain']:>13}")

#条件查询
def searchType(t):
    for i in mydict:
        if t == mydict[i]['type']:
            print(f"{i:<8}{mydict[i]['type']:>6}{mydict[i]['count']:>13}{mydict[i]['money']:>14}{mydict[i]['time']:>20}"
                  f"{mydict[i]['explain']:>13}")

#增加账务
def add():
    while True:
        id = input("输入编号：")
        if id in mydict:
            print("已有该编号")
            continue
        type = input("输入类型：")
        count = input("输入账户：")
        money = input("输入金额：")
        time = input("输入时间：")
        explain = input("输入说明：")
        mydict[id] = {"type": type, "count": count, "money": money, "time": time, "explain": explain}
        break

#修改账务
def update():
    while True:
        id = input("输入编号：")
        if id not in mydict:
            print("没有该编号请检查后重新输入")
            continue
        type = input("输入类型：")
        count = input("输入账户：")
        money = input("输入金额：")
        time = input("输入时间：")
        explain = input("输入说明：")
        mydict[id] = {"type": type, "count": count, "money": money, "time": time, "explain": explain}
        break

#主页面
print("欢迎进入小满家庭记账系统".center(50, "*"))
admin = {"admin":123456}
user = {"lisi":123456}
mydict = {"1":{"type":"吃饭支出","count":"交通银行","money":247,"time": '2020-01-01', "explain": "家庭聚餐"}}

while True:
    print("1、管理员登录")
    print("2、用户登录")
    print("3、退出系统")

    option = input("请输入你的选择：")
    # 管理员登录
    if option == '1':
        for x in range(3):
            username = input("请输入你的用户名:")
            passwd = int(input("请输入你的密码:"))
            if login(username, passwd):
                print("登录成功！")
                while True:
                    print("1、添加账务  2、删除账务  3、修改账务  4、查询账务  5.退出")
                    option = input("请输入你的选择：")
                    # 登录
                    if option == '1':
                        add()
                    elif option == '2':
                        x = input("输入你要删除的编号")
                        if int(x) < len(mydict):
                            print("请输入正确编号")
                            continue
                        mydict.pop(x)
                        print("删除成功")
                    elif option == '3':
                        update()
                    elif option == '4':
                        search()
                    elif option == '5':
                        break
                    else:
                        print("请输入正确的数")
                        continue
# 用户登录
    elif option == '2':
        for x in range(3):
            username = input("请输入你的用户名:")
            passwd = int(input("请输入你的密码:"))
            if loginu(username, passwd):
                print("登录成功！")
                while True:
                    print("1、查询所有   2、条件查询    3、退出")
                    option = input("请输入你的操作：")
                    if option == '1':
                        search()
                    elif option == '2':
                        t = input("输入查询账单类别")
                        searchType(t)
                    elif option == '3':
                        break
                    else:
                        print("请输入正确的数")
                        continue
    elif option == '3':
        break

    else:
        print("请输入正确数字")
        continue

